﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SportStore.Models;
using System.Text;

namespace SportStore.HtmlHelpers
{
    public static class PagingHelpers
    {
        public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo,string category, Func<int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder();
            TagBuilder tag1 = new TagBuilder("select");
            tag1.InnerHtml += "<option>4</option>";
            tag1.InnerHtml += "<option>16</option>";
            tag1.InnerHtml += "<option>64</option>";
            tag1.MergeAttribute("onchange", "changeItemsPerPage(this);");
            tag1.MergeAttribute("class", "changeItemsPerPage");
            result.Append(tag1.ToString());
            if(category==null) category="null";
            for (int i = 1; i <= pagingInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", "#"+pageUrl(i).Substring(1));
                tag.MergeAttribute("onclick", "navigateTo('" + category+"/Pages/"+ i+"');");
                if (i == pagingInfo.CurrentPage) tag.AddCssClass("selected");
                tag.InnerHtml = i.ToString();
                result.Append(tag.ToString());
            }
            return MvcHtmlString.Create(result.ToString());
        }
    }
}